package com.twu.biblioteca;

import java.util.Arrays;
import java.util.List;

public abstract class Collection {
    List<Item> items;

    Collection(Item... books) {
        this.items = Arrays.asList(books);

    }

    public boolean checkOut(String name) {
        for (Item item : items) {
            if (item.name.equals(name)) {
                return item.checkOut();
            }
        }
        return false;
    }

    public boolean checkIn(String name) {
        for (Item item : items) {
            if (item.name.equals(name)) {
                return (item.checkIn());
            }
        }
        return false;
    }

    public String toString() {
        StringBuilder ret = new StringBuilder();
        for (Item item : items) {
            if (!item.available()) {
                ret.append(item);
            }
        }
        if (ret.length() == 0) {
            ret.append("No ").append(getItemName()).append(" In Library");
            return ret.toString();
        }
        return getTitles() + ret.toString();
    }

    protected abstract String getItemName();

    public abstract String getTitles();
}
